/**
 * Created by liubin on 2015/09/18.
 */
'use strict';

import history from 'common/history';
import { FAIL } from 'actions/baseAction';
import { AUTH } from 'actions/authAction';

const authMiddleware = store=> next=> action => {
    if (action.status === FAIL && action.type === AUTH ) {
        // 没有登录，跳回登录画面
        // 这里给个延时，让状态能更新到
        return function cancel() {
            setTimeout(() => {
                history.replaceState(null, '/login');
            }, 500);
        }();
    } else {
        return next(action);
    }
};
export default authMiddleware;